<?php
//此文档为算法赛报名页
require_once("./bm_header.php");
$is_admin = isset($_SESSION['administrator']) || isset($_SESSION[$BM_ADMIN]);
if (isset($_GET['cid']))
{
	$cid=intval($_GET['cid']);
	require_once("./judgecid.php");//判断查看权限、比赛id合法性等等非正常访问
	$sid=intval($_GET['sid']);
	
	$ckind = $_GET['ckind'];
	if($ckind == 0)
	{
		if(!$is_admin && ($now < $contest_0_start || $now > $contest_0_end))
		{
				echo "<script language='javascript'>\n";
				echo "alert('未在注册时间，不可删除!');\n";
				echo "history.go(-1);\n";
				echo "</script>";
				require_once("bm_footer.php");
				exit(0);
		}
	}
	else 
	{
		if(!$is_admin && ($now < $contest_1_start || $now > $contest_1_end))
		{
				echo "<script language='javascript'>\n";
				echo "alert('未在注册时间，不可删除!');\n";
				echo "history.go(-1);\n";
				echo "</script>";
				require_once("bm_footer.php");
				exit(0);
		}
	}
	
	$user_id = $_SESSION['user_id'];
	
	//读教练信息
	$sql="SELECT * FROM `cr_user` WHERE `user_id`='$user_id' ";
	$result=mysql_query($sql);
	$row=mysql_fetch_object($result);	
	$school = $row->user_school;
	mysql_free_result($result);
	
	$team_id = $_GET['tid'];
	$sql="SELECT * FROM `cr_stu` WHERE `stu_id`='$sid' ";
	$result=mysql_query($sql);
	$rows_cnt=mysql_num_rows($result);
	if($rows_cnt == 0)
	{
			echo "<script language='javascript'>\n";
			echo "alert('没有这样一名队员!');\n";
			echo "history.go(-1);\n";
			echo "</script>";
			mysql_free_result($result);
			require_once("bm_footer.php");
			exit(0);
	}
	$row=mysql_fetch_object($result);
	if($row->stu_school != $school)//如果教练不是这个队伍的学校的（只有通过修改get的网址才会遇到这情况）
	{
			echo "<script language='javascript'>\n";
			echo "alert('没有删除权限!');\n";
			echo "history.go(-1);\n";
			echo "</script>";
			mysql_free_result($result);
			require_once("bm_footer.php");
			exit(0);
	}
	
	
	mysql_free_result($result);
	$sql="DELETE FROM `cr_stu` WHERE `stu_id`=$sid";
	mysql_query($sql);// or die(mysql_error());
}
	
?>


<?php
require_once("bm_footer.php");
?>

<script language=javascript>
	history.go(-1);
</script>